<template>
  <div class="page flex-column">
    <div class="page-title">
      <span class="location-part"><a href="/#/selected-content/list">精选内容</a></span>
      <span class="location-split">/</span><span class="location-current">全部软件</span>
    </div>
    <div class="software-result flex-column">
      <div class="result-title">软件列表</div>
      <a-flex v-if="isNotEmpty(storeAllSoftware.softwareSource)" wrap="wrap" gap="20" class="result-list">
        <software-card v-for="item in storeAllSoftware.softwareSource" :key="item.id" :softwareInfo="item" />
      </a-flex>
      <div v-else class="empty-list">
        <div class="empty-box">
          <img src="@/assets/images/empty-course.png" />
          <div class="empty-tip">
            <div class="empty-label">无内容</div>
          </div>
        </div>
      </div>

      <div v-if="totalRecords>pageSize" class="software-pagination flex-row flex-center">
        <a-pagination 
          v-model:current="currentPage"
          v-model:pageSize="pageSize"
          :total="totalRecords"
          @change="handlePageChange"
          show-less-items />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onBeforeMount, watch } from 'vue';
import { isNotEmpty } from "@/utils";
import useAllSoftwareStore from '@/stores/all-software';
import SoftwareCard from '@components/SoftwareCard.vue';
import { miscApi } from "@/services";

const storeAllSoftware = useAllSoftwareStore();
const currentPage = ref(storeAllSoftware.pageNum);
const pageSize = ref(storeAllSoftware.pageSize);
const totalRecords = ref(0);

onBeforeMount(async () => {
  goTop()
  await storeAllSoftware.initData();

  totalRecords.value = storeAllSoftware.totalRecords;

  await miscApi.traceViewPage("/selected-content/softwares");
});
const handlePageChange = (page, pageSize) =>{
  storeAllSoftware.handlePageChange(page, pageSize)
  goTop()
}
const goTop = () => {
  window.scrollTo({
    top: 0,
    behavior: 'smooth' 
  });
}
</script>

<style lang="less" scoped>
.page {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: @white-bg;

  .page-title {
    height: 22px;
    line-height: 22px;
    font-size: 16px;
    font-weight: 400;
    padding: 20px 30px;

    .location-part {
      cursor: pointer;
    }

    .location-split {
      padding: 0 2px;
    }

    .location-part, .location-split {
      color: @font-grey-light;
    }

    .location-current {
      color: @font-black;
    }
  }

  .software-filter {
    height: 400px;
    background-color: @white;
    border-radius: 20px;
    margin: 20px 30px 0 30px;
    padding: 22px 20px 10px 20px
  }
  .software-result {
    background-color: @white;
    border-radius: 20px;
    margin: 20px 30px;

    .result-title {
      height: 24px;
      line-height: 24px;
      font-size: 20px;
      font-weight: 500;
      color: @font-black;
      padding: 20px;
    }

    .result-list {
      margin: 25px;

      .software-card {
        width: calc(25% - 15px);
      }
    }

    .empty-list {
      height: 940px;
      display: flex;
      flex-direction: column;
      align-items: center;

      .empty-box {
        width: 510px;
        height: 309px;
        margin-top: 120px;
        position: relative;
        display: flex;
        justify-content: center;

        img {
          width: 100%;
          height: 100%;
        }

        .empty-tip {
          position: absolute;
          bottom: 0px;
          height: 16px;
          line-height: 16px;
          font-size: 16px;
          font-weight: 400;
          display: flex;
          flex-direction: row;
          align-items: center;

          .empty-label {
            color: @font-grey;
          }

          .empty-btn {
            color: @text-link-color;
          }
        }
      }
    }
  }
  .software-pagination {
    width: 100%;
    padding: 30px 30px 60px 30px;
  }
}

:deep(.ant-pagination) {
  .ant-pagination-item {
    min-width: 44px;
    height: 44px;
    margin-inline-end: 10px;
    line-height: 44px;
    background-color: @white;
    border: 1px solid @border-red-light;
    border-radius: 50%;

    a {
      font-size: 14px;
      font-weight: 400;
    }

    &.ant-pagination-item-active {
      border: 1px solid #ED171F;
    }
  }
  .ant-pagination-prev, .ant-pagination-next, .ant-pagination-jump-prev, .ant-pagination-jump-next {
    min-width: 44px;
    height: 44px;
    color: @font-black;
    line-height: 44px;
    border: 1px solid @border-red-light;
    border-radius: 50%;
    margin-inline-end: 10px;

    a {
      font-size: 14px;
      font-weight: 400;
      border-radius: 50%;
    }
  }

  .ant-pagination-prev:hover .ant-pagination-item-link, .ant-pagination-next:hover .ant-pagination-item-link {
    background-color: rgba(0, 0, 0, 0.06);
  }

  .ant-pagination-prev .ant-pagination-item-link, .ant-pagination-next .ant-pagination-item-link {
    border-radius: 50%;
  }

  .ant-pagination-options {
    display: none;
  }
}
</style>
